// pages/me/me.js.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    iconUrl: 'cloud://banmanshop.6261-banmanshop-1301943798/product.png', //用户头像地址
    nickName: '', //用户昵称
    level: '', //用户等级
    array: [{
        src: 'cloud://banmanshop.6261-banmanshop-1301943798/myCollect.png',
        text: "我的收藏",
        id: 1
      },
      {
        src: 'cloud://banmanshop.6261-banmanshop-1301943798/myCircle.png',
        text: "我的圈子",
        id: 2
      },
      {
        src: 'cloud://banmanshop.6261-banmanshop-1301943798/wdzz.png',
        text: "我的地址",
        id: 3
      },
      {
        src: 'cloud://banmanshop.6261-banmanshop-1301943798/aqzx.png',
        text: "安全中心",
        id: 4
      },
    ],
    codeUrl: 'cloud://banmanshop.6261-banmanshop-1301943798/code.png	', //二维码图片地址
    userInfo: {}
  },
  //点击登录跳转“登录”页面
  toLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  // 点击挑战待付款页面
  toDaiFuKuan() {
    if (app.globalData.xcxOpenId == '') {
      wx.showToast({
        title: '请先登录再查看待付款喔~',
        icon: 'none'
      })
      return
    }
    wx.navigateTo({
      url: '/pages/myOrder/myOrder?name=1',
    })
  },
  // 点击挑战待付款页面
  toDaiShouHuo() {
    if (app.globalData.xcxOpenId == '') {
      wx.showToast({
        title: '请先登录再查看待收货喔~',
        icon: 'none'
      })
      return
    }
    wx.navigateTo({
      url: '/pages/myOrder/myOrder?name=2',
    })
  },
  // 点击挑战退换货页面
  toTuiHuanHuo() {
    if (app.globalData.xcxOpenId == '') {
      wx.showToast({
        title: '请先登录再查看退换货喔~',
        icon: 'none'
      })
      return
    }
    wx.navigateTo({
      url: '/pages/myOrder/myOrder?name=3',
    })
  },
  // 点击跳转到“个人二维码”页面
  toPersonalCode() {
    wx.navigateTo({
      url: '/pages/personalCode/personalCode',
    })
  },
  ToZC: function () {
    wx.navigateTo({
      url: '/pages/Z  C/Z  C'
    })
  },
  toXingzuan: function () {
    wx.navigateTo({
      url: '/pages/xingzuan/xingzuan'
    })
  },
  toset() {
    wx.navigateTo({
      url: '../setUp/setUp',
    })
  },
  tonextPage(e) {
    const id = e.currentTarget.dataset.id
    if (app.globalData.xcxOpenId == '') {
      wx.showToast({
        title: '请先登录再查看喔~',
        icon: 'none'
      })
      setTimeout(function () {
        wx.reLaunch({
          url: '../me/me',
        })
      }, 1500)
      return
    }
    if (id == 1) {
      wx.navigateTo({
        url: '../myCollection/myCollection',
      })
    } else if (id == 2) {
      wx.navigateTo({
        url: '../myCircle/myCircle',
      })
    } else if (id == 3) {
      wx.navigateTo({
        url: '../addressSet/addressSet',
      })
    } else if (id == 4) {
      wx.navigateTo({
        url: '../setPassword/setPassword',
      })
    }
  },
  getUser() {
    var that = this
    // // console.log(app.globalData.xcxOpenId)
    wx.request({
      url: app.globalData.baseUrl + '/user/getUserByOpenId',
      data: {
        xcxOpenId: app.globalData.xcxOpenId
      },
      success(res) {
        if (res.data.code == 0) {
          that.setData({
            userMsg: res.data.data,
            nickName: res.data.data.nickName ? res.data.data.nickName : '',
            level: res.data.data.level ? res.data.data.level : ''
          })
        }
      }
    })
  },
  login() {
    var that = this
    wx.navigateTo({
      url: '../login/login',
    })
  },
  // 跳转“全部订单页面”
  toOrder() {
    wx.navigateTo({
      url: '/pages/myOrder/myOrder',
    })
  },
  toshangjia(e) {
    // console.log(e)
    const id = this.data.userMsg.nature
    if (id == 2) {
      wx.navigateTo({
        url: '../businessCenter/businessCenter'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      userInfo: app.globalData.userInfo
    })
  },
  onShow() {
    this.onLoad()
    this.getUser()
  }
})